package com.itheima.homework04;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.util.List;

public class XmlDemo02 {
    public static void main(String[] args) throws DocumentException {
        // 1、创建一个Dom4J框架提供的解析器对象
        SAXReader sr = new SAXReader();

        // 2、使用saxReader对象把需要解析的XML文件读成一个Document对象
        Document document = sr.read("books.xml");

        // 3、从文档对象中解析XML文件的全部数据了
        Element root = document.getRootElement();
        System.out.println(root.getName());
        List<Element> elements = root.elements();
        for (Element element : elements) {
            System.out.println(element.elementText("name"));
            System.out.println(element.elementText("publishingHouse"));
            System.out.println(element.elementText("dateOfPublication"));
            System.out.println(element.elementText("price"));
        }
    }
}
